home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: C constant expression declarations
- Date: 15 Feb 1996 20:45:10 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Feb15134510@qcd.lanl.gov>
- References: <31229735.41C67EA6@isi.com> <DMto56.Lo3@uns.bris.ac.uk>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: nathan@pact.srf.ac.uk's message of Thu, 15 Feb 1996 14:55:54 GMT
-
- In article <DMto56.Lo3@uns.bris.ac.uk> nathan@pact.srf.ac.uk (Nathan
- Sidwell) writes:
- <snip>
- However, a gotcha is using signed constants, for example
-
- #define EXPR -1
- if(a EXPR) ...
-
- this will complile as 'a - 1', rather than give a syntax error
-
- leaving out the brackets, will not affect correct code, but can cause
-
- #include <stdio.h>
- int main(void) {
- printf("%d\n",EXPR["\3\2\1"+1])
- return 0;
- }
-
- :-)
-
- incorrect code to be compiled to something undesired, rather than give
- an error. Having brackets o unsigned constants, just reinforces the habit.
-
- Even wih the brackets, I could still have silent error, for instance
-
- #define EXPR (-1)
- int a(int);
- if(a EXPR) ...
-
- will be compiled as 'a(-1)'. However this compounds two errors, using
- a function name instead of a variable (I assume you meant to compare
- a variable with a value), and omit the comparison operator.
-
- Or maybe one error? Trying to test if a == (int(*)(int))0 + 1; ?
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-